import {baseEffects, baseReducers, baseState} from "../../../../models/baseModel";

export default {
  namespace: 'refund',

  state: {
    ...baseState,
  },

  reducers: {
    ...baseReducers
  },

  effects: {

    ...baseEffects,

    * getPageInfo({payload}, {call, put}) {

      const p = {
        ...payload,
        baseUrl: getBaseUrl(),
        process: (records) => {
          return records.map(record => {
            const {totalFee, refundFee, settlementRefundFee} = record;
            return {
              ...record,
              totalFee: totalFee / 100+"元",
              refundFee: refundFee / 100+"元",
              settlementRefundFee: !!settlementRefundFee ? settlementRefundFee / 100+"元" : ""
            }
          });
        }
      }

      yield put({
        type: 'baseGetPageInfo',
        payload: p
      });
    },

    // 保存和修改
    * save({payload}, {put}) {

      yield put({
        type: 'baseSave',
        payload: {...payload, baseUrl: getBaseUrl()}
      });
    },


    // 删除 之后查询分页
    * delete({payload}, {call, put, select}) {

      yield put({
        type: 'baseDelete',
        payload: {...payload, baseUrl: getBaseUrl()}
      });
    },

    * getAll({payload}, {put, call}) {

      yield put({
        type: 'baseGetAll',
        payload: {...payload, baseUrl: getBaseUrl()}
      });
    }
  }

}

function getBaseUrl() {
  return "/refund";
}

